package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.UClass;
import com.wanbangee.marksystem.service.ClassManageService;

@RestController
public class ClassManageController {
	
	@Autowired
	private ClassManageService classManageService;  //注入班级管理的service
	
	/**
	 * 根据年级ID查询班级信息
	 * @param graId  年级ID
	 * @return
	 */
	@GetMapping("/classManage/selectClassInfoByGraId")
	public Map<String, Object> selectClassInfoByGraId(@RequestParam(value="graId") Integer graId){
		//用来存储提示信息，和状态码，数据
		Map<String, Object> responseMap = new HashMap<String, Object>();
		
		//调用classManageService中的selectClassInfoBySchIdAndGraId方法根据年级ID查询班级信息
		List<UClass> uClasss = classManageService.selectClassInfoBySchIdAndGraId(graId);
		
		if(uClasss == null || uClasss.size() == 0) {
			//查询返回的年级信息为null或者没有，返回状态码10013，学校还未设置年级
			responseMap.put("code", 10013);
			responseMap.put("msg", "不存在班级信息");
		}else {
			//查询得到了年级信息，将数据添加到map中，返回给客户端
			responseMap.put("uClasss", uClasss);
			//返回状态码1001，提示信息：接口成功
			responseMap.put("code", 1001);
			responseMap.put("msg", "接口成功");
		}
		return responseMap;
	}
}
